#!/bin/bash

set -eu

port="$1"
suite="$2"

function test_synchronous_http_get {
    response="$("$repo/tools/level-ip" "$repo/apps/curl/curl" 10.0.0.5 $port | strip_http_header)"

    diff "$folder/curl-fixture.txt" <(echo "$response")
}

function test_poll_http_get {
    response="$("$repo/tools/level-ip" "$repo/apps/curl-poll/curl-poll" 10.0.0.5 $port | strip_http_header)"

    diff "$folder/curl-fixture.txt" <(echo "$response")
}

function test_tcp_connection_refused {
    "$repo/tools/level-ip" "$repo/apps/curl/curl" 10.0.0.5 9999 2>&1 | grep -q "Connection refused"
}

test_run "test_synchronous_http_get" "$suite"
test_run "test_poll_http_get" "$suite"
test_run "test_tcp_connection_refused" "$suite"
